include ./Rules.make
LIB_MODULES := $(patsubst ./components/rules/%/rules.mak,%,$(wildcard ./components/rules/*/rules.mak))
LIB_MODULES += HisiDecSendStream HisiDecVpssCtl mpp_master
export PRJ_PATH

APP_DIR = $(PRJ_PATH)/app
LIBS_DIR = $(APP_DIR)/components
LIBS_SRC_DIR = $(LIBS_DIR)/src

PROCESS := decoder
PROCESS += daemon


all:components
	@for dir in $(LIB_MODULES); do  $(MAKE)  -s -C$(LIBS_SRC_DIR)/$$dir BUILD_TYPE=release  && $(MAKE)  -C$(LIBS_SRC_DIR)/$$dir install||exit "$$?"; done
	@for dir in $(LIB_MODULES); do  $(MAKE)  -s -C$(LIBS_SRC_DIR)/$$dir install||exit "$$?"; done
	@for dir in $(PROCESS); do  $(MAKE)  -s -C$(APP_DIR)/$$dir BUILD_TYPE=release ||exit "$$?"; done	

git:
	mkdir -p $(LIBS_DIR);cd $(LIBS_DIR) && \
	dos2unix ./bootstrap && \
	./bootstrap --host=arm-hisiv300-linux && \
	$(MAKE) all
	mkdir -p $(PRJ_PATH)/include
	mkdir -p $(PRJ_PATH)/release
	
components:
	@echo -e "***********build libs:\n$(LIB_MODULES)\n************"
	@for dir in $(LIB_MODULES); do  $(MAKE)  -s -C$(LIBS_SRC_DIR)/$$dir BUILD_TYPE=release  && $(MAKE)  -C$(LIBS_SRC_DIR)/$$dir install||exit "$$?"; done
	@for dir in $(LIB_MODULES); do  $(MAKE)  -s -C$(LIBS_SRC_DIR)/$$dir install||exit "$$?"; done
	
libs_clean:
	@for dir in $(LIB_MODULES); do  $(MAKE)  -s -C$(LIBS_SRC_DIR)/$$dir BUILD_TYPE=release  clean||exit "$$?"; done
		
install:
	@for dir in $(PROCESS); do  $(MAKE)  -s -C$(APP_DIR)/$$dir install ||exit "$$?"; done	
	$(MAKE) -f$(APP_DIR)/odin_cpy.mak $@
	mv $(APP_DIR)/_install/app_driver/*.out $(APP_DIR)/_install/app_driver/bins/

clean:
	@for dir in $(PROCESS); do  $(MAKE)  -s -C$(APP_DIR)/$$dir clean ||exit "$$?"; done	
	
distclean:clean
	$(MAKE)  -s -C$(LIBS_DIR)/ distclean

.PHONY:  install all clean git components distclean libs_clean
